package com.zzyl.web.chatApi;

import okhttp3.*;
import com.google.gson.Gson;
import java.io.IOException;

public class DeepSeekClient {

    private static final String API_URL = "https://api.deepseek.com";
    private static final String API_KEY = "sk-13f983d3e8f4476ca682b6380352d09e"; // 从安全配置获取

    private final OkHttpClient httpClient = new OkHttpClient();
    private final Gson gson = new Gson();

    public String sendRequest(String input) throws IOException {
        // 构造请求体（JSON格式）
        RequestBody body = RequestBody.create(
                MediaType.parse("application/json"),
                gson.toJson(new DeepSeekRequest(input))
                );

        // 构造请求
        Request request = new Request.Builder()
                .url(API_URL)
                .addHeader("Authorization", "Bearer " + API_KEY)
                .addHeader("Content-Type", "application/json")
                .post(body)
                .build();

        // 发送请求并处理响应
        try (Response response = httpClient.newCall(request).execute()) {
            if (!response.isSuccessful()) {
                throw new IOException("请求失败: " + response.code() + " - " + response.message());
            }
            return response.body().string();
        }
    }

    // 定义请求体结构（根据API文档调整）
    private static class DeepSeekRequest {
        private String model = "deepseek-chat";
        private String prompt;

        public DeepSeekRequest(String prompt) {
            this.prompt = prompt;
        }
    }


}